package com.homedo.odin.solution.enumcode.usersafe;

import java.util.Arrays;
import lombok.Getter;

/**
 * Created by liyi on 2018/5/22. 白名单状态 0：待审核，1：审核通过，-1：审核不通过
 */
@Getter
public enum UserSafeStatusEnum {

    TO_AUDIT(0, "待审核"),
    APPROVED(1, "审核通过"),
    AUDIT_FAILURE(-1, "审核不通过");

    private Integer dbValue;
    private String displayValue;

    UserSafeStatusEnum(Integer dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(UserSafeStatusEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(UserSafeStatusEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(UserSafeStatusEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
